{include file='public:header-css'/}
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    {include file='public:left-menu'/}
    <!--End 左侧导航-->
    <!--头部信息-->
    {include file='public:nav-header' title="商品管理" subTitle="添加编辑监控分类"/}
    <!--End 头部信息-->

    <!--页面主要内容-->
    <main class="lyear-layout-content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-body">
                <form method="post" id="submit-form" class="row">
                  <div class="form-group col-md-12">
                    <label class="form-title"><em class="require">*</em>分类名称</label>
                    <input type="text" class="form-control" name="name" value="{$info.name}" placeholder="请输入分类名称"/>
                    <span class="error" id="err_name"></span>
                  </div>
                  <div class="form-group col-md-12">
                    <h5>是否显示</h5>
                    <div class="btn-group form-group-toggle">
                      <label class="radio-btn radio-theme {if $info.is_open==1}active{/if}">
                        <input type="radio" name="is_open" value="1" {if $info.is_open==1}checked{/if}>
                        <i class="mdi mdi-checkbox-marked-circle-outline"> 是</i>
                      </label>
                      <label class="radio-btn radio-default {if $info.is_open==0}active{/if}">
                        <input type="radio" name="is_open" value="0" {if $info.is_open==0}checked{/if}>
                        <i class="mdi mdi-close-circle-outline"> 否</i> </label>
                    </div>
                  </div>
                  <div class="form-group col-md-12">
                    <label class="form-title"><em class="require">*</em>分类排序</label>
                    <input type="text" class="form-control" name="sort" value="{$info.sort|default=50}" placeholder="请输入排序"/>
                    <span class="help">将按照数字从小到大排序</span>
                    <span class="error" id="err_sort"></span>
                  </div>
                  <div class="col-md-12">
                    <input type="hidden" name="{$info.pk}" value="{$info[$info.pk]}">
                    <button type="button" class="btn-theme submit-btn">确定</button>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript">
  $(function(){
    $('.submit-btn').click(function () {
      $('span.error').hide();
      $('span.error').parent().removeClass('has-error');
      var url = "{:url('Goods/add_edit_classify')}";
      var data = $('#submit-form').serialize();
      $.ajax({
        type: "POST",
        url: url,
        data: data,
        dataType: 'json',
        success: function (data) {
          if (data.code == 1) {
            showSuccessMsg(data.msg, function () {
              if (data.data.url) {
                location.href = data.data.url;
              }
            });
          } else if (data.code == 10) {
            showErrorMsg(data.msg);
            $.each(data.data.result, function(index, item) {
              $('#err_' + index).text(item).show();
              $('#err_' + index).parent().addClass('has-error');
            });
          } else {
            showErrorMsg(data.msg);
          }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          showMsg("网络失败，请刷新后重试!");
        }
      });
    });
  });
</script>
</body>
</html>